<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>promise介绍</title>
</head>
<body>
    <script>
        let api = new Promise((resolve,reject)=>{
            setTimeout(()=>{
                if(true){//promise状态为pending
                    resolve('ok')
                }else{
                    reject('error')
                }

            },2000)
        });

        // api => promise
        //api.then( )=>promise.then()

        api.then(()=>{
            console.log(res);
            console.log('promise请求成功');
        })

        .catch((error)=>{
            console.log(error)
            console.log('请求失败')
        })
    </script>
</body>
</html>